<?php

namespace common\models;

use builder\behaviors\DatetimeBehavior;
use Yii;

/**
 * This is the model class for table "{{%email_record}}".
 *
 * @property int $id ID
 * @property string $category 邮件种类
 * @property string|null $content 邮件内容
 * @property string $code 验证码
 * @property int $sender 发送人
 * @property string $receive_email 接收邮箱
 * @property string $created_at
 */
class EmailRecord extends \builder\base\BaseActiveRecord
{
    /**
     * 重构日期行为配置
     * @return array
     */
    public function behaviors()
    {
        $behaviors = parent::behaviors();
        $behaviors['timestampBehavior'] = [
            'class' => DatetimeBehavior::class,
            'attributes' => [
                self::EVENT_BEFORE_INSERT => ['created_at'],
            ],
        ];

        return $behaviors;
    }

    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return '{{%email_record}}';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['category', 'content', 'sender', 'receive_email'], 'required'],
            [['content'], 'string'],
            [['sender'], 'integer'],
            [['created_at'], 'safe'],
            [['category', 'receive_email'], 'string', 'max' => 255],
            [['code'], 'string', 'max' => 10],
        ];
    }

    /**
     * {{@inheritdoc}}
     */
    public function scenarios()
    {
        $scenarios = parent::scenarios();
        // 新增
        $scenarios['SCE_Er_Create'] = ['category', 'content', 'code', 'sender', 'receive_email'];

        return $scenarios;
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'category' => '邮件种类',
            'content' => '邮件内容',
            'code' => '验证码',
            'sender' => '发送人',
            'receive_email' => '接收邮箱',
            'created_at' => '记录时间',
        ];
    }
}
